<template>
  <div class="user">
    <div class="list">
        <avue-crud :data="data" :option="option" :page.sync="page1" @size-change="sizeChange" @current-change="currentChange"></avue-crud>

    </div>
  </div>
</template>

<script>
import axios from 'axios'
export default {

  name:"user",
  data() {
      return {
        page1: {
          currentPage: 1,
          total: 0,
          layout: "total,pager,prev, next",
          background:false,
          pageSize: 10
        },
        data: [

        ],
        option: {
          align: 'center',
          menuAlign: 'center',
          addBtn:false,
          menu:false,
          column: [
            {
              label: "姓名",
              prop: 'nickname'
            },
            {
              label: "账号",
              prop: 'phonenum'
            },{
              label:"性别",
              prop:"sex"
            },{
              label:"学院",
              prop:"collage"
            },{
              label:"时间",
              prop:"buildtime"
            },{
              label:"禁用",
              prop:"stuAuth"
            }
          ]
        }
      }
    },
    mounted(){
      
    },
    created() {
      this.getList()
    },
    methods: {
      getList() {
        axios.post('apis/pc_userinfo').then(res=>{
          this.page1.total = res.data.data.length
          if (this.page1.currentPage === 1) {
            this.data = res.data.data
            this.data.forEach(item=>{
              if(item.sex === 1 ||  item.sex === null){
                item.sex = '男'
              }else{
                item.sex = '女'
              }
              if(item.stuAuth === 0 || item.stuAuth === null){
                item.stuAuth = "否"
              }else{
                item.stuAuth = "是"
              }
              console.log(item.buildtime);
               function rTime(date) {
                var json_date = new Date(date).toJSON();
                return new Date(new Date(json_date) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '') 
                }
                let iTime= rTime(item.buildtime)
                item.buildtime = iTime
            })
          }
         
      })
      },
      sizeChange(val) {
        this.page1.currentPage = 1
        this.page1.pageSize = val
        this.getList()
        this.$message.success('行数' + val)
      },
      currentChange(val) {
        this.page1.currentPage = val
        this.getList()
        this.$message.success('页码' + val)
      }
    }
}
</script>

<style scoped>
  .list{
    width: 88%;
    padding: 20px;
    text-align: center;
    
  }
  

</style>